﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Syngine.Components.Shapes
{
	public sealed class DrawableRectangle : Shape
	{
		private Rectangle _bounds;

		/// <summary>
		/// 
		/// </summary>
		/// <param name="bounds"></param>
		public DrawableRectangle(Rectangle bounds) : this(bounds, Color.White)
		{
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="bounds"></param>
		/// <param name="color"></param>
		public DrawableRectangle(Rectangle bounds, Color color) : base(color)
		{
			Bounds = bounds;
		}

		/// <summary>
		/// 
		/// </summary>
		public Rectangle Bounds
		{
			get
			{
				return _bounds;
			}
			set
			{
				_bounds = value;
				InitializeCore();
			}
		}

		protected override void InitializeCore()
		{
			Vertices = new VertexPositionColor[5];
			Vertices[0] = new VertexPositionColor(new Vector3(Bounds.X, Bounds.Y, 0.0f), Color);
			Vertices[1] = new VertexPositionColor(new Vector3(Bounds.X + Bounds.Width, Bounds.Y, 0.0f), Color);
			Vertices[2] = new VertexPositionColor(new Vector3(Bounds.X + Bounds.Width, Bounds.Y + Bounds.Height, 0.0f), Color);
			Vertices[3] = new VertexPositionColor(new Vector3(Bounds.X, Bounds.Y + Bounds.Height, 0.0f), Color);
			Vertices[4] = new VertexPositionColor(new Vector3(Bounds.X, Bounds.Y - 1, 0.0f), Color);
		}
	}
}
